using System.Configuration;
using System.Data;
using System.Windows;
using System.Windows.Navigation;
using DryIoc.Microsoft.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using WpfAppPrismT1.Services;
using WpfAppPrismT1.Views;

namespace WpfAppPrismT1;

public partial class App : PrismApplication
{
    protected override void RegisterTypes(IContainerRegistry containerRegistry)
    {
        containerRegistry.RegisterForNavigation<Page1View>();
        containerRegistry.RegisterForNavigation<Page2View>();
    }

    protected override IContainerExtension CreateContainerExtension()
    {
        if (_serviceCollection == null)
        {
            throw new InvalidOperationException(
                "Application Startup Error. Cannot found microsoft dependency injection service collection"
            );
        }

        ConfigureServicesWhenAppLaunch(_serviceCollection);

        var container = new DryIoc.Container(CreateContainerRules());
        var newContainer = container.WithDependencyInjectionAdapter(_serviceCollection);

        AppContainer = newContainer;

        return new DryIocContainerExtension(newContainer);
    }

    protected override Window CreateShell()
    {
        return Container.Resolve<MainWindow>();
    }
}
